#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 50 + 10;
const int MOD = 1e9 + 7;
int t, n, a[MAXN];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> t;
    while (t--) {
        cin >> n;
        int m = 2e7;
        ll res = 0;
        for(int i=1; i<=n; i++) cin>>a[i], m = min(m, a[i]);
        for(int i=1; i<=n; i++) {
            res += (a[i]-m);
        }
        cout << res << endl;
    }
    return 0;
}